package com.ado.abyss.core.web.controller;

import java.util.List;

import com.ado.abyss.core.params.http.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ado.abyss.core.dal.model.SysDept;
import com.ado.abyss.core.service.SysDeptService;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author adonais
 * @date 2020/06/08
 * @description 机构控制器
 *
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/dept")
public class DeptController {

	@Autowired
	@Qualifier(value = "sysDeptService")
	private SysDeptService sysDeptService ;
	
	
	@PreAuthorize("hasAuthority('sys:dept:add') AND hasAuthority('sys:dept:edit')")
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysDept record) {
		return HttpResult.ok(sysDeptService.save(record));
	}

	@PreAuthorize("hasAuthority('sys:dept:delete')")
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<SysDept> records) {
		return HttpResult.ok(sysDeptService.deleteBatch(records));
	}

	@PreAuthorize("hasAuthority('sys:dept:view')")
	@GetMapping(value="/findTree")
	public HttpResult findTree() {
		return HttpResult.ok(sysDeptService.findTree());
	}

}
